package xyz.xuminghai.javafx_learn.scene.effect;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.Blend;
import javafx.scene.effect.ColorInput;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

/**
 * 2023/7/21 8:53 星期五<br/>
 * 使用预定义的BlendMode之一将两个输入混合在一起的效果。
 *
 * @author xuMingHai
 */
public class BlendApp extends Application {

    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {

        Rectangle rectangle = new Rectangle(400, 300);

        Blend blend = new Blend();
        double width = rectangle.getWidth();
        double height = rectangle.getHeight() / 2;

        ColorInput colorInput1 = new ColorInput(0.0, 0.0,
                width, height, Color.RED);
        blend.setTopInput(colorInput1);

        ColorInput colorInput2 = new ColorInput(0.0, height,
                width, height, Color.BLUE);
        blend.setBottomInput(colorInput2);

        rectangle.setEffect(blend);

        root.setCenter(rectangle);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
